#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
__title__ = ""
__author__ = "Administrator"
__mtime__ = "2016/6/17"
"""
# 将多个TXT文件合并成一个文件


import os, sys, glob


def dirTxtToLargeTxt(dir, outputFileName):
    if not os.path.isdir(dir):
        print 'wrong input，%s is not a dir ' % dir
        return False
    outputFile = open(outputFileName, "a")

    for txtFile in glob.glob(os.path.join(dir, "*.txt")):
        print txtFile
        inputFile = open(txtFile, 'rb')
        for line in inputFile:
            outputFile.write(line)
    return True


if __name__ == "__main__":
    if len(sys.argv) < 3:
        print "Usage: %s dir outputFileName" % sys.argv[0]
        sys.exit()
    dirTxtToLargeTxt(sys.argv[1], sys.argv[2])
